﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CustomerManager
{
    public partial class FrmMain : Form
    {

        #region "Global Variables"
        public int status;
        public enum ExeAction
        {
            View,
            Add
        }
        #endregion

        #region "Constructor & Application_Load"
        public FrmMain()
        {
            InitializeComponent();
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            frmLogin.loadfrmmain();
            frmLogin.BringToFront();
            LogedIn(false);
        }
        #endregion

        #region "Usable Methods"
        public void LogedIn(bool b)
        {
            tsbtnLogin.Visible = !b;
            tsbtnCustomer.Visible = b;
            tsbtnDept.Visible = b;
            tsbtnReport.Visible = b;
            txbtnLogout.Visible = b;
            if (b)
                frmCustomer.BringToFront();
            else
                frmLogin.BringToFront();
            ChangeBtnBG(tsbtnCustomer);
        }

        public void ChangeBtnBG(object sender)
        {
            tsbtnCustomer.BackgroundImage = null;
            tsbtnDept.BackgroundImage = null;
            tsbtnExit.BackgroundImage = null;
            tsbtnLogin.BackgroundImage = null;
            txbtnLogout.BackgroundImage = null;
            tsbtnReport.BackgroundImage = null;

            ((ToolStripButton)sender).BackgroundImage = Properties.Resources.btn_bg;
        }

        public void loadcustomer()
        {
            frmCustomer.loadfrmmain();
            frmCustomer.LoadCustomer(status);
         
        }
        #endregion

        #region "Application Events"
        private void tsbtnCustomer_Click(object sender, EventArgs e)
        {
            ChangeBtnBG(sender);
            frmCustomer.LoadCustomer(status);
            frmCustomer.BringToFront();
        }

        private void tsbtnDept_Click(object sender, EventArgs e)
        {
            ChangeBtnBG(sender);
            frmDebt.LoadCustomer(status);
            frmDebt.loadfrmmain();
            frmDebt.BringToFront();
        }

        private void tsbtnReport_Click(object sender, EventArgs e)
        {
            ChangeBtnBG(sender);
            frmReport.LoadCustomer(status);
            frmReport.BringToFront();
        }

        private void txbtnLogout_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Bạn muốn đăng xuất phải không?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    LogedIn(false);
                    ChangeBtnBG(tsbtnLogin);
                    frmLogin.BringToFront();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
        }

        private void tsbtnExit_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
        #endregion
    }
}
